<template>

	<view class="history-data">


		<!-- 标题 -->
		<view class="navbar">
			<u-icon @click="navigateBack" class="icon-left" name="arrow-left" color="#333" size="50"></u-icon>
			<text>宝宝症状</text>
			<!-- 	<view class="" style="width:100%;">
				
			</view> -->
			<view @click="goWrite" class=""
				style='text-align:center;margin-top:6px;width: 100px;font-size:18px;background-color: #4CD964;border-radius: 5px;color:#fff;float:right;margin-top:45px;height:34px;line-height: 34px;margin-right:20px;'>
				填写症状
			</view>
		</view>

		<!-- 时间选择 -->
		<view class="calendar" @click="calendarOptions.show= true" style="margin-top:48px;">
			<u-icon name="arrow-left" style="float: left;padding-top: 25rpx;"></u-icon>
			<image style="width: 40rpx;height: 40rpx;position: absolute;top: 23%;left: 34%;"
				src="https://srmzln.oss-cn-hangzhou.aliyuncs.com/znl/images/calendar.png" mode=""></image>
			<text style="position: absolute;top: 2%;padding-left: 10rpx;left: 40%;">{{pageOptions.time}}</text>
			<u-icon name="arrow-right" style="float: right;padding-top: 25rpx;"></u-icon>
		</view>

		<view class="main-content">
			<view class="content" v-for='(item,idx) in list' :key='idx'>
				<view class="timer">
			{{pageOptions.time.substring(5)}}	{{item.start.substring(11)}}-{{item.end.substring(11)}}
				</view>
				<view class="symptom-list" >
					<view class="item" v-for='(ele,index) in item.symptom' :key='index' style="margin:8px 0 0 12px">
						{{ele}}
					</view>
				<!-- 	<view class="item" style="margin-left:20px">
						咳嗽
					</view> -->
				</view>
				<view class="tip">
				
					<span   style='color:#1a1a1a'> 系统分析：</span> {{checkIsCool(item.symptom)? `宝宝有${item.symptom}等症状,请及时给宝宝治疗。`:`宝宝有${item.symptom}等症状,有感冒风险。`}}
				</view>
			</view>
		</view>





		<u-calendar v-model="calendarOptions.show" mode="date" @change="handleCalendarChange"></u-calendar>
	</view>
</template>

<script>
	export default {
		components: {



		},
		data() {
			return {
				list: [],

				calendarOptions: {
					show: false
				},
				pageOptions: {
					time: this.today()
				},


			}

		},
		onShow() {



		},

		mounted() {

			this.getSymptom(0)


		},
		onLoad() {

		},

		methods: {
			checkIsCool(symptom){
				const str = symptom.join()
				if(str.includes('咳嗽')||str.includes('低烧')||str.includes('高烧')){
					return true
				}else{
					return false
				}
			},
			async getSymptom(e) {
			let timer = ''
		
			if(this.pageOptions.time===this.today()){
				timer = this.now()
			}else{
				timer = `${this.pageOptions.time} 23:59:59`
			}
			let tpl_param = {}
			// if(e!=0){
			 tpl_param = {
				date: timer
			}
			// }
			

				// uni.showLoading({
				// 	title: '加载中',
				// 	mask: true,
				// });
				const res = await this.$api.searchDeviceState(tpl_param);
				if (res.code === 200) {
					const list = res.result.list[0].symptomList
					this.list = list
					if (list.length) {
						list.forEach(ele => {
							ele.symptom = ele.symptom.split(',')
						})
					}else{
						if(this.today()===this.pageOptions.time){
						this.goWrite()
						}
					}
					console.log(list, 134)
					// uni.hideLoading()
				} else {
					uni.showToast({
						title: res.message || '获取数据失败'
					});
				}
			},
			now() {
				var myDate = new Date();
				var year = myDate.getFullYear(); //获取当前年
				var mon = myDate.getMonth() + 1; //获取当前月
				if (mon < 10) {
					mon = "0" + mon;
				}
				var date = myDate.getDate(); //获取当前日
				if (date < 10) {
					date = "0" + date;
				}
				var hours = myDate.getHours(); //获取当前小时
				if (hours < 10) {
					hours = "0" + hours;
				}
				var minutes = myDate.getMinutes(); //获取当前分钟
				if (minutes < 10) {
					minutes = "0" + minutes;
				}
				var seconds = myDate.getSeconds(); //获取当前秒
				if (seconds < 10) {
					seconds = "0" + seconds;
				}
				let dates = `${year}-${mon}-${date} ${hours}:${minutes}:${seconds}`
				return dates
			
			},
			goWrite() {
				// uni.navigateTo({
				// 	url: '../histroy/HistroyWriteSymptom?date=' + this.pageOptions.time
				// })
				uni.navigateTo({
					url:'writeSymptoms/writeSymptoms?date'+ this.pageOptions.time
				})
			},
			today() {
				var myDate = new Date();
				var year = myDate.getFullYear(); //获取当前年
				var mon = myDate.getMonth() + 1; //获取当前月
				if (mon < 10) {
					mon = "0" + mon;
				}
				var date = myDate.getDate(); //获取当前日
				if (date < 10) {
					date = "0" + date;
				}
				var hours = myDate.getHours(); //获取当前小时
				if (hours < 10) {
					hours = "0" + hours;
				}
				var minutes = myDate.getMinutes(); //获取当前分钟
				if (minutes < 10) {
					minutes = "0" + minutes;
				}
				var seconds = myDate.getSeconds(); //获取当前秒
				if (seconds < 10) {
					seconds = "0" + seconds;
				}
				let dates = `${year}-${mon}-${date}`
				return dates

			},



			navigateBack() {
				uni.switchTab({
					url: '../index'
				})
			},
			handleCalendarChange(e) { // 选择日期
				console.log(e)
				this.pageOptions.time = e.result
				this.getSymptom()

			}
		}
	}
</script>
<style scoped lang="scss">
	.main-content {
		width: 100%;
		padding: 15px 12px;
		box-sizing: border-box;

		.content {
			width: 100%;
			margin-top:15px;
			background-color: #F1F1F1;
			border-radius: 6px;
			min-height: 200px;
			padding: 16px;
			box-sizing: border-box;

			.timer {
				font-size: 16px;
				color: #3d3d3d;
			}

			.symptom-list {
				width: 100%;
				display: flex;
				justify-content: left;
				margin-top: 5px;
				flex-wrap: wrap;
				.item {
					width: 80px;
					background-color: #e0e0ff;
					text-align: center;
					line-height: 30px;
					height: 30px;
					color: #3d3d3d;
					border-radius: 5px;
				}

			}

			.tip {
				margin-top: 15px;
				color: #767676;
				font-size: 18px;
			}
		}
	}

	.Tips {
		display: flex;
		margin: 20rpx;
		margin-top: 50rpx;
	}

	.Tips>view {
		height: 250rpx;
		background-color: #F6F7FB;
		border-radius: 30rpx;

		box-shadow: 1px 1px 2px rgb(228, 227, 227), 0 0 5px rgb(228, 227, 227), 0 0 1px rgb(228, 227, 227);
	}

	// 温馨提示
	.tips_join {
		flex: 1;
		padding: 20rpx;
	}

	.tips_join>image {
		width: 40rpx;
		height: 40rpx;
	}
	.active-item{
		margin-left:20px !important;	}
	.tips_join>view {
		// margin-top: 10rpx;
		text-align: center;
		font-size: 16px;
		color: #253DC2;
	}

	.tips_join>text {
		font-size: 16px;
		font-weight: bold;
		margin-left: 10rpx;
		color: #FF5310;
	}

	.uni-ec-canvas {
		width: 100%;
		height: 100%;
		display: block;
	}

	.history-data {
		overflow: hidden;
	}



	.navbar {
		margin-top: 90rpx;
		margin-bottom: 20rpx;
		width: 750rpx;
	}

	.navbar>text {
		font-size: 36rpx;
		font-weight: bold;
		padding-left: 220rpx;
	}

	.icon-left {
		margin-top: 20rpx;
		margin-left: 10rpx;
	}

	// 日历
	.calendar {
		background-color: rgb(241, 241, 241);
		position: relative;
		height: 80rpx;
		line-height: 80rpx;
		margin-left: 25rpx;
		margin-right: 25rpx;
		padding-left: 50rpx;
		padding-right: 50rpx;
		border-radius: 50rpx;
	}



	.uni-ec-canvas {
		margin-top: 22rpx;
		width: 100%;
		height: 640rpx;
		display: block;
	}
</style>
